package com.analysis.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.analysis.common.FileUtil;
import com.analysis.service.SimpleKMeansService;

import weka.clusterers.SimpleKMeans;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;

public class SimpleKMeansServiceImpl implements SimpleKMeansService {
	private String libaryPath = "./kline/libary.txt";
	
	public void run() throws Exception{
		List<String> datas = FileUtil.readLines(libaryPath);
		List<String[]> clustersDatas = datas.parallelStream().map(each->{
			String[] strs = each.split(",");
			return new String[]{strs[3],strs[4],strs[5]};
		}).collect(Collectors.toList());
		
		
		DataSource source = new DataSource("C:/Users/Jchen25/Desktop/Stock/libary.csv");
		 
		Instances instances = source.getDataSet();
//		instances.
//		System.out.println(instances.get(0).toString());
		
		SimpleKMeans simpleKmeans = new SimpleKMeans();
		simpleKmeans.setNumClusters(50);
		simpleKmeans.buildClusterer(instances);
		
//		FileUtil.write("./kline/simpleKmeans.txt", simpleKmeans);
		
		System.out.println(Arrays.toString(simpleKmeans.getClusterSizes()));
	}
	
	public static void main(String[] args) {
		try {
			new SimpleKMeansServiceImpl().run();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
